package com.lagou.factory;

import java.lang.reflect.Method;
import java.util.List;

/**
 * desc: 代理工厂
 *
 * @author tengfei wang
 * @version 1.0
 * @date Created in 7/9/2020
 */
public class ProxyFactory {

    private final AopProxy aopProxy;

    public ProxyFactory() {
        this.aopProxy = new DynamicProxy();
    }

    public ProxyFactory(AopProxy aopProxy) {
        this.aopProxy = aopProxy;
    }

    public Object getProxy(Object o) {
        return aopProxy.createProxy(o);
    }

    /**
     * 获取带事务的代理对象
     *
     * @param o       需要代理的对象
     * @param methods 代理对象中需要代理的方法集合
     * @return 增强事务之后的代理对象
     */
    public Object getProxyWithTransaction(Object o, List<Method> methods) {
        return aopProxy.createProxyWithTransaction(o, methods);
    }

}
